package karaoke.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import karaoke.excepcion.DAOExcepcion;
import karaoke.modelo.Evento;
import karaoke.negocio.GestionEventos;


/**
 * Servlet implementation class RecuperaPostServlet
 */
@WebServlet("/admin/EventosServlet")
public class EventosServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EventosServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	   
       

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String idlocals = request.getParameter("idLocal");				
        int idlocal = Integer.parseInt(idlocals);        
        String cadena = request.getParameter("NombreLocal");

        Collection<Evento> eventos = null;
		GestionEventos negocio = new GestionEventos();
		try {
			eventos = negocio.buscarPorLocalyNombre(idlocal,cadena);
		
		} catch (DAOExcepcion e) {
			System.out.println("Error en el servlet ahhh");
		}
		
		// Guardando datos en el scope REQUEST
		request.setAttribute("EVENTOS_ENCONTRADOS", eventos);		
		request.setAttribute("selectedLocal", idlocal);

		RequestDispatcher rd = request.getRequestDispatcher("Eventos.jsp");
		rd.forward(request, response);

	}

}
